package com.bitbakery.plugin.cl.lang;

import com.bitbakery.plugin.cl.lang.psi.CLDefmacro;
import com.bitbakery.plugin.cl.lang.psi.CLDefun;
import com.bitbakery.plugin.cl.lang.psi.CLElement;
import com.bitbakery.plugin.cl.lang.psi.CLFile;
import com.intellij.ide.structureView.StructureViewTreeElement;
import com.intellij.ide.structureView.TextEditorBasedStructureViewModel;
import com.intellij.ide.util.treeView.smartTree.Filter;
import com.intellij.ide.util.treeView.smartTree.Grouper;
import com.intellij.ide.util.treeView.smartTree.Sorter;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;

public class CLStructureViewModel extends TextEditorBasedStructureViewModel {
    private static final Class SUITABLE_CLASSES[] = new Class[]{
            CLDefun.class, CLDefmacro.class, CLFile.class
    };

    private CLElement myRoot;

    public CLStructureViewModel(final CLElement root) {
        super(root.getContainingFile());
        myRoot = root;
    }

    @NotNull
    public StructureViewTreeElement getRoot() {
        return new CLStructureViewElement(myRoot);
    }

    @NotNull
    public Grouper[] getGroupers() {
        return Grouper.EMPTY_ARRAY;
    }

    @NotNull
    public Sorter[] getSorters() {
        return new Sorter[]{Sorter.ALPHA_SORTER};
    }

    @NotNull
    public Filter[] getFilters() {
        return Filter.EMPTY_ARRAY;
    }

    protected PsiFile getPsiFile() {
        return myRoot.getContainingFile();
    }

    @NotNull
    protected Class[] getSuitableClasses() {
        return SUITABLE_CLASSES;
    }
}
